The Davies-Meyer Transform

Compression hash functions with fixed-length inputs can be constructed from block ciphers using the Davies-Meyer transform. In particular, given a block cipher with key-length and block length , we can build a compression function as follows:

Essentially, we parse the -bit string as a key of length and a string of length . The encryption algorithm is invoked on the string with the key and the resulting "ciphertext" is then XOR-ed with to produce the hash of .

In practice, one never uses common block ciphers such as AES when implementing Davies-Meyer functions because these ciphers are designed to be fast when encrypting a long message with the same key. However, when combined within the Merkle-Damgård transform Davies-Meyer functions work with relatively short inputs and keys which change for each input. Additionally, common block ciphers have smaller output lengths than is necessary for most hash functions - AES has 128-bit outputs which is a big no no because birthday attacks will be able to find collisions after only tries (something feasible on a modern computer). Therefore, block ciphers used for the implementation of Davies-Meyer functions are specifically designed for this very purpose and have outputs of length 512 or even 1024 bits.

Security

It is unknown how to prove that is collision resistant solely based on the fact that the block cipher uses a pseudorandom permutation. However, we can prove collision resistance if the block cipher is ideal. This means that the cipher uses a truly random permutation - the only way to know the output of for a specific and key is to actually evaluate because every output is equally likely.

Theorem: Davies-Meyer Collision Resistance

If the Davies-Meyer function is implemented using an ideal block cipher , then the probability that any attacker who queries with queries can find a collision is at most .

Proof: Davies-Meyer Collision Resistance

Since the cipher is ideal, the function is a truly random permutation, and, in particular, for every key the function is also a truly random permutation (contrast this to the case of pseudorandom permutations, where this holds true only if the key is uniformly chosen).

The attacker is given oracle access to and tries to find two strings such that . After parsing these strings as and , the adversary's goal reduces to finding and such that .

We assume that the adversary is "smart" in the sense that they never make the same query twice (otherwise they would just be wasting their own time) and that they never query with a ciphertext whose plaintext they already know, lest they again waste their own time.

Consider the adversary's -th query. A query to reveals only the hash . Similarly, a query to , will only reveal the hash . A collision only occurs if for some .

Fix with . When making the -th query, the value of is already known, since it was obtained in a previous query. A collision occurs only if the adversary queries and obtains or they query and obtain . Each event occurs with probability at most

This is true because the adversary has already made queries and has therefore made at most previous queries with the same key . Since they are not repeating queries, there are (at most) fewer possible inputs the adversary can use for . The probability of a collision at the -th step is then the probability that the adversary makes an encryption query and obtains a collision or they make a decryption query and obtain a collision, i.e.

Since (comparing with the birthday attack), can be at most and for sufficiently large , we have which gives

The probability of a collision in queries can be expressed as

By the union bound, we obtain

The number of distinct pairs which satisfy is exactly which is upper bounded by . Ultimately, we have that